import {
  signid
} from '@/utils/index'
  // import custormClass from '../class/custormClass'
export default {
  components: {
  },
  computed: {
  },
  created() {
  },
  data() {
    return {
      $editKey: -1,
      custormList: [], // 渲染自定义组件的数据
      custormCurrent: -1,
      draggingCurrent: -1,
      loading: false
    }
  },
  mounted() {
    // console.log(custormClass.create({ el: 1, params: 2 }))
  },
  methods: {
    checkCopy() {
      let redataItem = {}
      if (this.custormCurrent !== -1) {
        const key = this.custormList[this.custormCurrent]['key']
        let allnum = -1
        let nownum = -1
        const redataArray = [...this.redata1]
        redataArray.some(item => {
          const isredata = item.key === key
          if (isredata) {
            allnum = item.allnum
            nownum = item.nownum
            redataItem = item
            return isredata
          }
        })
        this.iscustormDataCopy = (allnum > nownum || !allnum)
        return redataItem
      } else {
        this.iscustormDataCopy = false
      }

      return redataItem
    },
    custormEditEvt({ type, params, data }) {
      console.log({ type, params, data }, '====================custormEditEvt')
      if (data) {
        if (data.type === '12') {
          this.$refs.chooseLink.formFormatData.formData.link_path = data.path
        } else if (data.type === '13') {
          this.$refs.chooseLink.formFormatData.formData.app_id = data.app_id
          this.$refs.chooseLink.formFormatData.formData.app_path = data.path
        } else if (data.type === '14') {
          this.$refs.chooseLink.formFormatData.formData.mobile = data.path
        } else if (params.envelope) {
          console.log(this.$refs.chooseLink.currentRow, 'currentRow')
          console.log(data, 'data')
          data.map(item => {
            this.$refs.chooseLink.currentRow.push(item.id)
          })
        }
      }
    },
    findCustormIndex(id) {
      if (!!id && id.length === 13 && (typeof id === 'string')) {
        const index = this.custormList.findIndex((item) => {
          return item.id === id
        })
        return index
      }
      return -1
    },
    checkCustorm(_key) {
      const index = this.custormList.findIndex((item, index) => {
        return item.key === _key
      })
      return index
    },
    filterCustorm(_key) {
      let _custormItem = {}
      console.log(this.custormInitData, '=====================cus')
      if (this.custormInitData.length > 0) {
        this.custormInitData.some((custormItem) => {
          const iscustorm = custormItem.key === _key
          if (iscustorm) {
            _custormItem = JSON.parse(JSON.stringify(custormItem))
            return iscustorm
          }
        })
      }
      _custormItem.id = signid('MC')
      return _custormItem
    },
    custormEvt(...arg) {
      console.log(...arg, '======================arg')
      const [evttype, ...last] = [...arg]
      console.log([evttype, ...last], '================evttype')
      this.$nextTick(() => {
        if (evttype === 'current') {
          this.custormCurrent = last[0]
          if (!this.noFiltersLits.includes(last[0])) {
            this.$nextTick(() => {
              this.checkCopy()
              this.watchCurrentScroll && this.watchCurrentScroll()
            })
          }
        } else if (evttype === 'dragging') {
          this.draggingCurrent = last[0]
        } else if (evttype === 'deleted') {
          this.$alert('确定删除此组件？', '提示', {
            confirmButtonText: '确定',
            callback: action => {
              if (action === 'confirm') {
                const current = this.custormList[last[0]]
                let _redataItem = {}
                const redata = [...this.redata1]
                redata.some((redataItem) => {
                  const isredata = redataItem.key === current.key
                  if (isredata) {
                    _redataItem = redataItem
                    return isredata
                  }
                });
                (_redataItem.nownum >= 1) && (_redataItem.nownum -= 1)
                this.custormList.splice(last[0], 1)
                this.custormCurrent = this.custormList.length >= 1 ? this.custormList.length - 1 : -1
                console.log(this.custormCurrent, '!!!')
                this.checkCopy()
                this.watchCurrentScroll && this.watchCurrentScroll('del')
                this.$message({
                  type: 'success',
                  message: `删除成功`
                })
              }
            }
          })
        }
      })
    }
  }
}
